package com.baowenli.mapper;

import com.baowenli.pojo.Worker;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface WorkerMapper {

    /**
     * 查询所有
     */
    @ResultMap(value="brandResultMap")
    List<Worker> selectAll();

    /**
     *  操作员登录
     *
     * */
    @ResultMap("brandResultMap")
    @Select("select * from worker_info where username = #{username} and password = md5(#{password}) and role = " +
            "'admin' and status = 1;")
    Worker selectById(@Param("username") String username,@Param("password") String password);


    /**
     *  管理员登录
     *
     * */
    @ResultMap("brandResultMap")
    @Select("select * from worker_info where username = #{username} and password = md5(#{password}) and role = " +
            "'operator' and status = 1;")
    Worker selectByIdMange(@Param("username") String username,@Param("password") String password);


    /**
     *  解雇操作员
     * */
    @Update("update worker_info set status = 0 where username = #{name} and password = md5(#{password}) and role = " +
            "'admin';")
    int DeleteWorker(@Param("name") String name,@Param("password") String password);

    /**
     *  晋升操作员
     * */
    @Update("update worker_info set role = 'operator' where username = #{name} and password = md5(#{password}) and " +
            "role " +
            "= " +
            "'admin' and status = 1;")
    int workerPromote(@Param("name") String name,@Param("password") String password);
}
